﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Mvc;

namespace Wicresoft.EKA.MVCExtensions
{
    public static class IoCRegister
    {

        private static Dictionary<string, IRegister> registers = new Dictionary<string, IRegister>();

        public static void WebApiRegister(System.Web.Http.Dispatcher.IHttpControllerActivator activator)
        {
            registers["webapi"] = (IRegister)activator;
            GlobalConfiguration.Configuration.Services.Replace(typeof(System.Web.Http.Dispatcher.IHttpControllerActivator), activator);
        }


        public static void MVCResigster(IControllerFactory factory)
        {
            registers["mvc"] = (IRegister)factory;
            ControllerBuilder.Current.SetControllerFactory(factory);
        }

        public static void Register<TFrom, TTo>() where TTo : TFrom
        {
            foreach (var item in registers.Values)
            {
                item.Register<TFrom, TTo>();
            }
        }

    }
}
